package com.jt9003.controller;


import com.jt9003.pojo.Price;
import com.jt9003.service.Price_paymentservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class Price_paymentcontroller {
    @Autowired
    private Price_paymentservice price_paymentservice;


    //查询未缴费患者列表和模糊查询
    @RequestMapping("/getpricelist")
    public Object getpricelist(
                                @RequestParam(value = "time", required = false) String time,
                                @RequestParam(value = "p_name", required = false) String p_name) {
        Map map = new HashMap();
        Map param = new HashMap();

        System.out.println(p_name + "==============================");
        String s = "";
        String end = "";
        if (time != null && time != "") {
            String[] date = time.split(" - ");
            s = date[0];
            end = date[1];
        }
        param.put("p_name", p_name);
        param.put("s", s);
        param.put("end", end);


        try {
             //查询数据
            List<Price> priceList = price_paymentservice.getpricelist(param);
            //获取总数
            int count = price_paymentservice.pricecount(map);
            map.put("result", priceList);
            map.put("success", true);
            map.put("message", "查询患者列表成功");
            map.put("code","0" );
            map.put("count",count);
            map.put("", "");
        } catch (Exception e) {
            map.put("success", false);
            e.printStackTrace();
            map.put("message", "查询患者列表失败");
        }
        return map;
    }


    //查看医生开的药（查看"药品按钮"）
    @RequestMapping("/findpriceyp")
    @ResponseBody
    public Object findpriceyp(
            @RequestParam(value = "p_name", required = false) String p_name

    ) {
        Map map = new HashMap();
        Map param = new HashMap();
        param.put("p_name", p_name);
        try {
            Price Price = price_paymentservice.findpriceyp(p_name);
            System.out.println(Price.getDr_name()+"==============");
            map.put("result", Price);
            map.put("success", true);
            map.put("message", "查询患者药品成功");
            map.put("code", "0");
            map.put("count", 1000);
            map.put("", "");
        } catch (Exception e) {
            map.put("success", false);
            map.put("message", "查询患者药品失败");
        }

        return map;
    }

    //查询划价缴费总数（根据医生名字参数查询）
    @RequestMapping("/pricecount")
    @ResponseBody
    public Object pricecount() {
        Map map = new HashMap();
        try {
            int count = price_paymentservice.pricecount(map);

            map.put("result", count);
            map.put("success", true);
            map.put("message", "查询列表总数成功");
        } catch (Exception e) {
            map.put("success", false);
            map.put("message", "查询列表总数失败");
        }
        return map;
    }

    //  根据挂号单号来查询未缴费的患者   （缴费按钮)

    @RequestMapping("/Updatalistjf")
    public Object updatalistjf(Price price) {
        int count = 0;
        Map<String, Comparable> map = new HashMap();
        try {
            System.out.println("===拿到的价格是===="+price.getPre_money());
           count = price_paymentservice.updatalistjf(price);
            map.put("result", count);
            map.put("success", true);
            map.put("message", "缴费成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("success", false);
            map.put("message", "缴费失败");
        }
        return map;
    }


}